package com.team.arms.yuding.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.team.arms.yuding.domain.VoluntaryInformation;
import com.team.arms.yuding.domain.dto.VoluntaryInformationDto;
import com.team.arms.yuding.domain.vo.VoluntaryInformationVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Entity com.team.arms.yuding.domain.VoluntaryInformationVo
 */
public interface VoluntaryInformationMapper extends BaseMapper<VoluntaryInformation> {

    //查询志愿填报信息
    List<VoluntaryInformationVo> selectAll();

//    @Select("select y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
//            "    from y_voluntary_information as y , b_culture_info as b\n" +
//            "    where\n" +
//            "    y.culture_id=b.culture_id and y.name like \"%${name}%\"")
//    List<VoluntaryInformationVo> selectByname(@Param("name") String name);
//
//    @Select("select y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
//            "    from y_voluntary_information as y , b_culture_info as b\n" +
//            "    where\n" +
//            "    y.culture_id=b.culture_id and y.batch_Id = #{batchId}")
//    List<VoluntaryInformationVo> selectByBatchId(@Param("batchId") String batchId);
//
//    @Select("select y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
//            "    from y_voluntary_information as y , b_culture_info as b\n" +
//            "    where\n" +
//            "    y.culture_id=b.culture_id and y.volunteer_one like \"%${selectByVolunteerOne}%\"")
//    List<VoluntaryInformationVo> selectByVolunteerOne(@Param("volunteerOne") String volunteerOne);
//
//    @Select("select y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
//            "    from y_voluntary_information as y , b_culture_info as b\n" +
//            "    where\n" +
//            "    y.culture_id=b.culture_id and y.volunteer_two like \"%${volunteerTwo}%\"")
//    List<VoluntaryInformationVo> selectByVolunteerTwo(@Param("volunteerTwo") String volunteerTwo);
//
//    @Select("select y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
//            "    from y_voluntary_information as y , b_culture_info as b\n" +
//            "    where\n" +
//            "    y.culture_id=b.culture_id and b.culture_program like \"%${cultureProgram}%\"")
//    List<VoluntaryInformationVo> selectByCultureProgram(@Param("cultureProgram") String cultureProgram);

    @Select("<script>select y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
            "    from y_voluntary_information as y , b_culture_info as b\n" +
            "    where y.culture_id=b.culture_id\n" +
            "    <if test=\"name != null and name != ''\">\n" +
            "        and name like CONCAT('%',#{name},'%')\n" +
            "    </if><if test=\"cultureProgram != null and cultureProgram != ''\">\n" +
            "        and culture_program like CONCAT('%',#{cultureProgram},'%')\n" +
            "    </if><if test=\"batchId != null and batchId != ''\">\n" +
            "        and batch_id like CONCAT('%',#{batchId},'%')\n" +
            "    </if><if test=\"volunteerOne != null and volunteerOne != ''\">\n" +
            "        and volunteer_one like CONCAT('%',#{volunteerOne},'%')\n" +
            "    </if><if test=\"volunteerTwo != null and volunteerTwo != ''\">\n" +
            "        and volunteer_two like CONCAT('%',#{volunteerTwo},'%')\n" +
            "    </if></script>")
    //按条件查询
    List<VoluntaryInformationVo> selectVoluntaryInformationVo(VoluntaryInformationDto voluntaryInformationDto);

    //新增志愿填报信息
    int insertAll(VoluntaryInformation voluntaryInformation);

    @Select(" select  y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
            "    from y_voluntary_information as y , b_culture_info as b\n" +
            "    where\n" +
            "    y.culture_id=b.culture_id\n" +
            "    and\n" +
            "    volunteer_info_id = #{volunteerInfoId,jdbcType=VARCHAR}")
    //按id查询志愿填报信息
    VoluntaryInformationVo selectById(@Param("volunteerInfoId") String volunteerInfoId);

    @Select(" select  y.volunteer_info_id,y.name,b.culture_program, y.batch_id, y.volunteer_one, y.volunteer_two\n" +
            "    from y_voluntary_information as y , b_culture_info as b\n" +
            "    where\n" +
            "    y.culture_id=b.culture_id\n" +
            "    and ${field} like CONCAT('%',#{content},'%')")
    List<VoluntaryInformationVo> selectByFiled(@Param("field") String field, @Param("content") String content);

    @Select("select b.culture_program\n" +
            "from y_voluntary_information as y , b_culture_info as b\n" +
            "where\n" +
            "y.culture_id=b.culture_id and volunteer_one = #{volunteerOne,jdbcType=VARCHAR}")
    List<String> selectCultureProgramByVolunteerOne(@Param("volunteerOne") String volunteerOne);

    @Update("<script>update y_voluntary_information as y,b_culture_info as b\n" +
            "set <if test=\"information.batchId != null and information.batchId != ''\">\n" +
            "y.batch_id = #{information.batchId,jdbcType=VARCHAR}\n" +
            "</if><if test=\"information.name != null and information.name != ''\">\n" +
            "y.name = #{name,jdbcType=VARCHAR}\n" +
            "</if><if test=\"information.volunteerOne != null and information.volunteerOne != ''\">\n" +
            "y.volunteer_one = #{information.volunteerOne,jdbcType=VARCHAR}\n" +
            "</if><if test=\"information.volunteerTwo != null and information.volunteerTwo != ''\">\n" +
            "y.volunteer_two = #{information.volunteerTwo,jdbcType=VARCHAR}\n" +
            "</if><if test=\"information.cultureProgram != null and information.cultureProgram != ''\">\n</if>" +
            "b.culture_program = #{information.cultureProgram,jdbcType=VARCHAR}\n" +
            "where y.culture_id=b.culture_id \n" +
            "and y.volunteer_info_id = #{volunteerInfoId,jdbcType=VARCHAR}</script>")
    int updateAll(@Param("information") VoluntaryInformationDto voluntaryInformation,@Param("volunteerInfoId") String volunteerInfoId);
}




